package leetcode.code1881;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution1 implements IDebug {
	public String maxValue(String n, int x) {
		int p = 0;
		StringBuffer ans = new StringBuffer(n);
		int X = x + '0';
		int len = n.length();
		if (n.charAt(0) == '-') {
			p++;
			while (p < len) {
				if (ans.charAt(p) > X) {
					break;
				}
				p++;
			}
		} else {
			while (p < len) {
				if (ans.charAt(p) < X) {
					break;
				}
				p++;
			}
		}
		return ans.insert(p, x).toString();
	}

	@Override
	public void debug1() {
		HelpDebug.compare("999", this.maxValue("99", 9));

	}

	@Override
	public void debug2() {
		HelpDebug.compare("6546421", this.maxValue("654621", 4));

	}

	@Override
	public void debug3() {
		HelpDebug.compare("-123", this.maxValue("-13", 2));

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
